package com.sesame;

import com.alibaba.fastjson.JSON;
import com.github.kevinsawicki.http.HttpRequest;
import kim.sesame.framework.utils.ImgBase64;

import java.io.File;
import java.util.HashMap;
import java.util.Map;

public class Test {
    public static void main(String[] args) {
//        uploadFile();
        uploadBase64();
    }

    public static void uploadFile() {
        File input = new File("C:\\Users\\wangjianghai\\Pictures\\carp\\2.png");

        String url = "http://127.0.0.1:8072/upload";

        HttpRequest request = HttpRequest.post(url);
        request.part("file", "timg.jpg", "multipart/form-data;", input);
        request.part("module", "fms/user");
        String result = request.body();

        System.out.println(result);
    }

    public static void uploadBase64() {
        String file = "C:\\Users\\wangjianghai\\Pictures\\carp\\2.png";
        String base64 = ImgBase64.conversionString(file);

        String url = "http://127.0.0.1:8072/upload";

        Map<String, String> map = new HashMap<>();
        map.put("module", "fms/user");
        map.put("fileBase64", base64);
        map.put("fileType", ".jpg");

        String result = HttpRequest.post(url).form(map).body();

        System.out.println(result);
    }
}
